package com.hoshiicloud.goods.mq;

import com.hoshiicloud.common.exception.ServiceException;
import com.hoshiicloud.common.utils.EncryptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.stereotype.Component;

import java.util.Base64;
import java.util.List;


/**
 * @program: hoshiicloud
 * @description: rabmitMQ消息消费业务处理
 * @author: Mr.wu
 * @create: 2019-06-01 15:15
 **/
@Slf4j
@Component
public class RabbitMQConsumer {

    /**
     * 冻结库存消息处理
     * @param message
     * @throws Exception
     */
//    @RabbitListener(queues = QueueConsts.LOCK_STOCK_QUEUE)
//    @RabbitHandler
    public void lockSkuStockProcess(Message message) {
        try {
            log.info("接受回调消息"+message.toString());
            //获取请求体转换
            String body= new String(message.getBody());
            log.info("body:"+body);
            System.out.println(body);
            String json= new String(Base64.getMimeDecoder().decode(body.replace("\r\n", ""))) ;
            List data= EncryptionUtil.decryptData(json,RsaConfig.getClientPublicKey(),RsaConfig.getServerPrivateKey(), List.class);
            if(data==null){
                //验签失败
                throw new ServiceException("解析消息失败，延签失败");
            }else{
                //todo
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.toString());
        }

    }
}
